package com.ktjy.ktmall.controller.vo;

import com.ktjy.common.annotation.Log;
import com.ktjy.common.core.controller.BaseController;
import com.ktjy.common.core.domain.AjaxResult;
import com.ktjy.common.core.page.TableDataInfo;
import com.ktjy.common.enums.BusinessType;
import com.ktjy.common.utils.poi.ExcelUtil;
import com.ktjy.ktmall.domain.vo.ShoppingVo;
import com.ktjy.ktmall.service.vo.ShoppingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/ktmall/shopping")
public class ShoppingController extends BaseController {
    @Autowired
    private ShoppingService shoppingService;

    /**
     * 查询商品关联属性列表
     */
    @PreAuthorize("@ss.hasPermi('ktmall:shopping:list')")
    @GetMapping("/list")
    public TableDataInfo list(ShoppingVo shoppingVo)
    {
        startPage();
        List<ShoppingVo> list = shoppingService.selectShoppingVoList(shoppingVo);
        return getDataTable(list);
    }


    /**
     * 导出商品关联属性列表
     */
    @PreAuthorize("@ss.hasPermi('ktmall:shopping:export')")
    @Log(title = "商品关联属性", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShoppingVo shoppingVo)
    {
        List<ShoppingVo> list = shoppingService.list();
        ExcelUtil<ShoppingVo> util = new ExcelUtil<ShoppingVo>(ShoppingVo.class);
        util.exportExcel(response, list, "商品关联属性数据");
    }

    /**
     * 获取商品关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('ktmall:shopping:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(shoppingService.getById(id));
    }

    /**
     * 新增商品关联属性
     */
    @PreAuthorize("@ss.hasPermi('ktmall:shopping:add')")
    @Log(title = "商品关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShoppingVo shoppingVo)
    {
        return toAjax(shoppingService.save(shoppingVo));
    }

    /**
     * 修改商品关联属性
     */
    @PreAuthorize("@ss.hasPermi('ktmall:shopping:edit')")
    @Log(title = "商品关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShoppingVo shoppingVo)
    {
        return toAjax(shoppingService.updateById(shoppingVo));
    }

    /**
     * 删除商品关联属性
     */
    @PreAuthorize("@ss.hasPermi('ktmall:shopping:remove')")
    @Log(title = "商品关联", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Integer> ids)
    {
        return toAjax(shoppingService.removeByIds(ids));
    }
}
